<%@ page import="java.io.PrintWriter" %>
<%@ page import="day20240922.managemans" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理页面</title>
</head>
<link href="MyCss.css" rel="stylesheet"
      integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<style>
    main {
        padding: 10px;
    }

    .div_main {
        background: #fafafa;
        margin: 0 20%;
    }

    .grid {
        padding: 20px 0;
        border-bottom: 1px solid #dbedf3;
    }

    .tit0 {
        font-size: 20px;
        color: #8a1253;
    }

    .tit1 {
        color: #e8751a;
        text-decoration: none;
        /* 清除默认边框 */
        border: 0;
        outline: none;
        /*清除默认背景 */
        background-color: transparent;
    }

</style>
<body>
<%! public Connection getConnection() throws SQLException, ClassNotFoundException {
    Class.forName("com.mysql.cj.jdbc.Driver");
    System.out.println("JDBC驱动加载成功！");
    String url = "jdbc:mysql://localhost:3306/manageman";
    String user = "root";
    String password = "lcw0909.";
    Connection connection = DriverManager.getConnection(url, user, password);
    return connection;
}%>
<header>
    <div>
        <!--        查询-->
        <nav class="navbar navbar-expand-lg bg-body-tertiary">
            <div class="container-fluid">
                <a class="navbar-brand" href="manage_jsp.jsp">返回管理页面</a>
                <a href="" style="text-decoration:none;">添加新学生</a>
                <div id="navbarSupportedContent">
                    <form action="find" method="get" class="d-flex" role="search">
                        <% String name0 = request.getParameter("name");
                            if (name0 == null) {
                                name0 = " ";
                            }%>
                        <input style="font-size: 20px; text-align: center" class="form-control me-2" name="name"
                               type="search" placeholder=<%= name0%>  aria-label="Search" readonly>
                        <button class="btn btn-outline-success" style="width: 80px">查找</button>
                    </form>
                </div>
            </div>
        </nav>

    </div>
    <div>
        <!--        新增-->
    </div>
</header>
<main>
    <div class="div_main text-center">
        <div class="grid">
            <div class="row">
                <div class="tit0 col">No.</div>
                <div class="tit0 col">Name</div>
                <div class="tit0 col">Age</div>
                <div class="tit0 col">Sex</div>
                <div class="tit0 col">Birthday</div>
                <div class="tit0 col"></div>
                <div class="tit0 col"></div>
            </div>
        </div>
        <% ArrayList<managemans> arrayList = new ArrayList<>();
            Connection connection = getConnection();
            String sql = "SELECT * FROM mm";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            ResultSet resultSet = preparedStatement.executeQuery();
            while (resultSet.next()) {
                int id = resultSet.getInt("id");
                String name1 = resultSet.getString("name");
                int age = resultSet.getInt("age");
                String sex = resultSet.getString("sex");
                Date birthday = resultSet.getDate("birthday");
                arrayList.add(new managemans(id, name1, age, sex, birthday));
            }%>
        <% ArrayList<managemans> arrayLists = new ArrayList<>();
            for (int i = 0; i < arrayList.size(); i++) {
                String name = arrayList.get(i).getName();
                if (name.equals(name0)) {
                    arrayLists.add(arrayList.get(i));
                }
            }
            for (managemans managemans : arrayLists) {
                int id = managemans.getId();
                int age = managemans.getAge();
                String sex = managemans.getSex();
                Date birthday = (Date) managemans.getBirthday();%>
        <form action="Delete" method="post">
            <div class="grid">
                <div class="row">
                    <div class="tit col"><%=id%>
                    </div>
                    <input type="hidden" name="userid-0" value=<%= id%>>
                    <div class="tit col"><%=name0%>
                    </div>
                    <div class="tit col"><%=age%>
                    </div>
                    <div class="tit col"><%=sex%>
                    </div>
                    <div class="tit col"><%=birthday%>
                    </div>
                    <div class="col"><a href="" class="tit1">修改</a></div>
                    <div class="col">
                        <button type="submit" class="tit1">删除</button>
                    </div>
                </div>
            </div>
        </form>
        <%}%>
    </div>
</main>


</body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-/mhDoLbDldZc3qpsJHpLogda//BVZbgYuw6kof4u2FrCedxOtgRZDTHgHUhOCVim"
        crossorigin="anonymous"></script>
</html>